import { getResponsetimepercentileApi, getScenceLatencyApi, getScenceThroughputApi } from '@/api/scence';
import _ from 'lodash';

export const remainingData = [
  {
    name: "ts-travel-service",
    status: "running",
    x: 300,
    y: 300,
    next: ["ts-basic-service", "ts-seat-service"],
  },
  {
    name: "ts-basic-service",
    status: "running",
    x: 800,
    y: 300,
    next: ["ts-station-service", "ts-train-service", "ts-route-service", "ts-price-service"],
  },
  {
    name: "ts-station-service",
    status: "running",
    x: 550,
    y: 100,
    next: ["mysql"],
  },
  {
    name: "ts-train-service",
    status: "running",
    x: 550,
    y: 100,
    next: ["mysql"],
  },
  {
    name: "ts-route-service",
    status: "running",
    x: 550,
    y: 100,
    next: ["mysql"],
  },
  {
    name: "ts-price-service",
    status: "running",
    x: 550,
    y: 100,
    next: ["mysql"],
  },

  {
    name: "ts-seat-service",
    status: "running",
    x: 550,
    y: 500,
    next: ["ts-order-service","ts-config-service"],
  },

  {
    name: "ts-order-service",
    status: "running",
    x: 550,
    y: 100,
    next: ["mysql"],
  },
  {
    name: "ts-config-service",
    status: "running",
    x: 550,
    y: 100,
    next: ["mysql"],
  },

]

export const cheapestData = [
  {
    name: "ts-travel-plan-service",
    status: "running",
    x: 300,
    y: 300,
    next: ["ts-route-plan-service", "ts-train-service", "ts-seat-service"],
  },
  {
    name: "ts-route-plan-service",
    status: "running",
    x: 800,
    y: 300,
    next: ["ts-travel-service", "ts-travel2-service"],
  },
  {
    name: "ts-travel-service",
    status: "running",
    x: 550,
    y: 100,
    next: ["ts-basic-service", "ts-seat-service", "ts-route-service"],
  },
  {
    name: "ts-travel2-service",
    status: "running",
    x: 550,
    y: 100,
    next: ["ts-basic-service", "ts-seat-service", "ts-route-service"],
  },


  {
    name: "ts-basic-service",
    status: "running",
    x: 550,
    y: 100,
    next: ["ts-station-service", "ts-train-service", "ts-route-service", "ts-price-service"],
  },
  {
    name: "ts-seat-service",
    status: "running",
    x: 550,
    y: 100,
    next: ["ts-order-service", "ts-config-service", "ts-order-other-service"],
  },

  {
    name: "ts-order-other-service",
    status: "running",
    x: 550,
    y: 100,
    next: ["mysql"],
  },

  {
    name: "ts-route-service",
    status: "running",
    x: 550,
    y: 100,
    next: ["mysql"],
  },

  {
    name: "ts-station-service",
    status: "running",
    x: 550,
    y: 100,
    next: ["mysql"],
  },
  {
    name: "ts-train-service",
    status: "running",
    x: 550,
    y: 100,
    next: ["mysql"],
  },
  {
    name: "ts-price-service",
    status: "running",
    x: 550,
    y: 100,
    next: ["mysql"],
  },
  {
    name: "ts-order-service",
    status: "running",
    x: 550,
    y: 100,
    next: ["mysql"],
  },
  {
    name: "ts-config-service",
    status: "running",
    x: 550,
    y: 100,
    next: ["mysql"],
  },
  
]


export const getData = (type: string) => {
  let data = []
  switch (type) {
    case 'remaining':
      data = _.cloneDeep(remainingData);
      break;
    case 'cheapest':
      data = _.cloneDeep(cheapestData);
      break;
    default:
      return []; // 添加默认情况，以防 type 不匹配任何 case
  }
  return data
}
export const selectOptions = [
  { 
    label: '查询余票',
    value: 'remaining',
    url: 'index.html',
    serviceName:'ts-travel-service',
    endpointName: 'POST:/api/v1/travelservice/trips/left',
  },
  {
    label: '查询最便宜的票',
    value: 'cheapest',
    url: 'client_adsearch.html',
    serviceName:'ts-travel-plan-service',
    endpointName:'POST:/api/v1/travelplanservice/travelPlan/cheapest',
  },
]

export const mutilpleLineColor = [
  '#55a2e5',
  '#69bdbf',
  '#f7ce6a',
  '#ed7386',
  '#a1a7e1',
]

export const formatQPSlegend = (key: string) =>{
  const percentage = parseFloat(key) * 100; 
  return `P${percentage}`;
}

export const chartKeyOptions = {
  "latencies": {
    legend:"平均响应时间",
    color:"#5c7bd9",
  },
  "throughputs": {
    legend:"平均每秒访问次数",
    color:"#73c0de",
  },
  "responsetimepercentile": {
    legend:"响应时间分位数",
    color: mutilpleLineColor,
  },
}
export const tabList = [
  {
    key: "latencies",
    tab: "平均响应时间",
    api: getScenceLatencyApi,
    isMinutePrecision: false,
    legend: ["平均响应时间"],
    unit: "时间(毫秒)",
    type: "single",
  },
  {
    key: "throughputs",
    tab: "平均每秒访问次数",
    api: getScenceThroughputApi,
    isMinutePrecision: false,
    legend: ["平均每秒访问次数"],
    unit: "次数",
    type: "single",
  },
  {
    key: "responsetimepercentile",
    tab: "响应时间分位数",
    api: getResponsetimepercentileApi,
    isMinutePrecision: false,
    legend: ["P50","P75","P90","P95","P99"],
    percent:[0.5,0.75,0.9,0.95,0.99],
    unit: "时间(毫秒)",
    type: "multiple",
  },
];